{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "promising-cedar",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/single-element-in-a-sorted-array/\n",
    "\n",
    "\n",
    "Runtime: 104 ms, faster than 8.62% of Python3 online submissions for Single Element in a Sorted Array.\n",
    "Memory Usage: 16.3 MB, less than 75.51% of Python3 online submissions for Single Element in a Sorted Array.\n",
    "\n",
    "\n",
    "\n",
    "```python\n",
    "class Solution:\n",
    "    def singleNonDuplicate(self, nums: List[int]) -> int:\n",
    "        #6:21\n",
    "        i = 0\n",
    "        length = len(nums)\n",
    "        if length == 1:\n",
    "            return nums[0]\n",
    "        while i < length:\n",
    "            num = nums[i]\n",
    "            if i - 1 >= 0 and i + 1 < length:\n",
    "                if nums[i-1] != num != nums[i+1]:\n",
    "                    return num\n",
    "            if i == 0 and i + 1 < length and i + 2 < length:\n",
    "                if nums[i] != nums[i+1] == nums[i+2]:\n",
    "                    return num\n",
    "            if i == length - 1 and i - 1 >= 0 and i - 2 >= 0:\n",
    "                if nums[i] != nums[i-1] == nums[i-2]:\n",
    "                    return num\n",
    "            i += 1\n",
    "        #6:42\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "useful-thought",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
